﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using TripsLogic.util;

namespace TripsLogic.controller
{
    public class TripController
    {
        public static DataTable getNewTrips(int num)
        {
            try
            {
                DataTable dt = DB.getData("SELECT TOP "+num+" * FROM TRIP WHERE DequeueTime is not Null ORDER BY DequeueTime DESC ;");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }
        public static int getCurrentSlot(int tripId)
        {
            int slot = Convert.ToInt32(DB.getValue("select COUNT (*) AS NumberOfOrders from TRIPJOIN where TripId= " + tripId + " and IsApproved = 1 and StatusId !=0;"));
            return slot;
        }
        public static DataTable getTripById(int num)
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM TRIP WHERE DequeueTime is not Null and Id="+num+" ;");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }

        public static string getCurrentId()
        {
            try
            {
                return DB.getValue("select IDENT_CURRENT('TRIP')");
            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getCurrentSliderId"));
                return "";
            }
        }
        public static DataTable getPreferenceList()
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM PREFERENCELIST;");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }
        public static DataTable getTripPreferenceById(int id)
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM TRIPPREFERENCE where TripId="+id+";");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }
        public static DataTable getPreferenceById(int id)
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM PREFERENCELIST WHERE Id="+id+";");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }
        public static DataTable getJoinbyTripId(int id)
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM TRIPJOIN WHERE TripId=" + id + " ;");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }
        public static DataTable getCarbyTripId(int id)
        {
            try
            {
                DataTable dt = DB.getData("SELECT * FROM CARLIST WHERE Id=" + id + " ;");
                return dt;

            }
            catch (Exception ex)
            {
                // log
                //LogController.createLog(new Log(DateTime.Now.ToString("yyyyMMddHHmmss"), ex.Message, 1, "Error getComments"));
                return null;
            }
        }

    }
}